fn main() {
    let s = String::from("Hello, world!");
    take_ownership(s);

    // println!("s: {}", s); 这里owner 已经转移了，这里s就不生效了

    let x = 5;

    makes_copy(x);
    println!("x: {}", x);

    let s1 = gives_ownership();

    println!("s1: {}", s1);

    let s2 = String::from("hello");

    println!("s2: {}", s2);
    let s3 = takes_and_gives_back(s2);

    println!("s3: {}", s3);

    let s4 = String::from("hello");

    let (s5, len) = calculate_length(s4);

    println!("The s5 length of '{}' is {}", s5,len);

    let s6 = String::from("hello");

    let len2 = calculate_length2(&s6);
    println!("The s6 length of '{}' is {}", s6,len2);

    let mut s7 = String::from("hello");

    let len3 = calculate_length3(&mut s7);
    println!("The s7 length of '{}' is {}", s7,len3);

}

fn take_ownership(some_string: String){
    println!("{}", some_string);
}

fn makes_copy(some_number: i32) {
    println!("{}", some_number);
}

fn gives_ownership() -> String {
    let some_string = String::from("hello");
    return some_string;
}

fn takes_and_gives_back(a_string: String) -> String {
    return a_string;
}

fn calculate_length(s: String) -> (String, usize) {
    let length = s.len();
    return (s, length);
}

fn calculate_length2(s: &String) -> usize {
    // s.push_str(", world");  不可以修改，因为不是mut的
    return s.len();
}

fn calculate_length3(s:  &mut String) -> usize {
    s.push_str(", world");
    return s.len();
}